<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="../vue.js" type="text/javascript"></script>
</head>
<body>
    <div id="app1">
        <h2>计数器：{{counter}}</h2>
        <!-- <button v-on:click="counter++">加</button>
        <button v-on:click="counter--">减</button> -->
        <button v-on:click="add">加</button>
        <button v-on:click="minus">减</button>
    </div>
    
    <script>
        // 方法 1
        // var app = new Vue({
        //     el: "#app1",
        //     data: {
        //         counter: 1
        //     }
        // })
            // 方法 2
        const app = new Vue({
            el: "#app1",
            data: {
                counter: 1
            },
            methods:{
                add: function(){
                    console.log("add");
                    this.counter++;
                },
                minus: function(){
                    console.log("minus");
                    this.counter--;
                }
            }
        })

    </script>
</body>
</html>